package cskevin.utils;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

/**
 * 文档工具
 * @author csKevin
 *
 */
public class DocUtils {

	/**
	 * 获取文档内容
	 * @param path
	 * @return
	 */
	public static String getDocContent(String path){
		//创建文档对象
				DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
				DocumentBuilder builder;
				try {
					builder = dFactory.newDocumentBuilder();					
					try {
						Document doc = builder.parse(new File(path));
						String content = doc.getTextContent();
						return content;
					} catch (SAXException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} 
				} catch (ParserConfigurationException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return null;
	}
}
